package main

import (
	"fmt"
	"net/http"
	"os"

	"github.com/julienschmidt/httprouter"
	"notabug.org/ropemann/imabon/src/common"
	"notabug.org/ropemann/imabon/src/routes/api"
	"notabug.org/ropemann/imabon/src/routes/web"
)

func main() {
	common.LoadConfig(".env")

	router := httprouter.New()
	useWeb := os.Getenv("USE_WEB")
	useApi := os.Getenv("USE_API")

	if useWeb == "Y" {
		web.RegisterWebRoutes(router, "public/html/*.html", false)
	}
	if useApi == "Y" {
		api.RegisterApiRoutes(router)
	}

	host := os.Getenv("HOST")
	port := os.Getenv("PORT")

	if len(host) == 0 {
		host = "http://localhost"
		os.Setenv("HOST", host)
	}
	if len(port) == 0 {
		port = ":8080"
		os.Setenv("PORT", port)
	}

	fmt.Printf("Server is on @ %s%s\n", host, port)
	http.ListenAndServe(port, router)
}
